package com.example.newsapp.ui.navigation

import android.content.Context
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import com.example.newsapp.data.compositionLocal.LocalNavControllerPicture
import com.example.newsapp.data.compositionLocal.LocalNavControllerTab
import com.example.newsapp.data.`object`.PictureNavigation
import com.example.newsapp.data.`object`.PictureState
import com.example.newsapp.ui.components.pictureComponent.sortList.BuildingPictureList
import com.example.newsapp.ui.components.pictureComponent.sortList.DrawPictureList
import com.example.newsapp.ui.components.pictureComponent.sortList.HotPictureList
import com.example.newsapp.ui.components.pictureComponent.sortList.PetPictureList
import com.example.newsapp.ui.components.pictureComponent.sortList.ScenePictureList
import com.example.newsapp.ui.components.pictureComponent.sortList.SuggestPictureList

@Composable
fun PictureNavigation(modifier: Modifier = Modifier) {
    var navControllerPicture = LocalNavControllerPicture.current
    // 图片标签导航图
    NavHost(
        navController = navControllerPicture,
        startDestination = PictureNavigation.suggestList
    ) {
        // 推荐图片列表
        composable(
            route = PictureNavigation.suggestList,
            enterTransition = {
                slideInHorizontally(
                    initialOffsetX = { -it }
                )
            },
            exitTransition = {
                slideOutHorizontally(
                    targetOffsetX = { -it }
                )
            }
        ) {
            SuggestPictureList()
        }
        // 热门图片列表
        composable(
            route = PictureNavigation.hotList,
            enterTransition = {
                slideInHorizontally(
                    initialOffsetX = { if (PictureState.previousTab < 1) it else -it}
                )
            },
            exitTransition = {
                slideOutHorizontally(
                    targetOffsetX = { if (PictureState.currentTab < 1) it else -it}
                )
            }
        ) {
            HotPictureList()
        }
        // 宠物图片列表
        composable(
            route = PictureNavigation.petList,
            enterTransition = {
                slideInHorizontally(
                    initialOffsetX = { if (PictureState.previousTab < 2) it else -it}
                )
            },
            exitTransition = {
                slideOutHorizontally(
                    targetOffsetX = { if (PictureState.currentTab < 2) it else -it}
                )
            }
        ) {
            PetPictureList()
        }
        // 风景列表
        composable(
            route = PictureNavigation.sceneList,
            enterTransition = {
                slideInHorizontally(
                    initialOffsetX = { if (PictureState.previousTab < 3) it else -it}
                )
            },
            exitTransition = {
                slideOutHorizontally(
                    targetOffsetX = { if (PictureState.currentTab < 3) it else -it}
                )
            }
        ) {
            ScenePictureList()
        }
        // 建筑图片列表
        composable(
            route = PictureNavigation.building,
            enterTransition = {
                slideInHorizontally(
                    initialOffsetX = { if (PictureState.previousTab < 4) it else -it}
                )
            },
            exitTransition = {
                slideOutHorizontally(
                    targetOffsetX = { if (PictureState.currentTab < 4) it else -it}
                )
            }
        ) {
            BuildingPictureList()
        }
        // 图画图片列表
        composable(
            route = PictureNavigation.drawList,
            enterTransition = {
                slideInHorizontally(
                    initialOffsetX = { if (PictureState.previousTab < 6) it else -it}
                )
            },
            exitTransition = {
                slideOutHorizontally(
                    targetOffsetX = { if (PictureState.currentTab < 6) it else -it}
                )
            }
        ) {
            DrawPictureList()
        }
    }
}